#include "kernel/types.h"
#include "kernel/stat.h"
#include "user/user.h"

//初始化
void Create_SqQueue(struct SqQueue *Q){
    Q->front = Q->rear = 0;
}

//判断队列是否为空
int IsEmpty(struct SqQueue *Q){
    return Q->front == Q->rear;
}

//求得队列长度
int SqQueue_Length(struct SqQueue *Q){
    return (Q->rear - Q->front + MAXSIZE) % MAXSIZE;
}

//队列元素入队
void Enter_SqQueue(struct SqQueue *Q, uint e){
    if((Q->rear + 1) % MAXSIZE == Q->front){
	    printf("Queue is full\n");
	    return;
    }
    Q->data[Q->rear] = e;               //在队尾指向的地址赋值
    Q->rear = (Q->rear + 1) % MAXSIZE;  //队尾指针进1
}

//队列元素出队
void Depart_SqQueue(struct SqQueue *Q, uint *e){
    if(IsEmpty(Q)){
	    printf("No elements in the queue\n");
	    return;
    }
    *e = Q->data[Q->front];             //取出队首指针指向的地址元素
    Q->front = (Q->front + 1) % MAXSIZE;//队首指针进1
}

//取队首
int Get_front(struct SqQueue *Q){
    if(IsEmpty(Q)){
	    printf("Queue is empty\n");
	    return -1;
    }
    return Q->data[Q->front];
}